package com.liu.user.controller;


import cn.dev33.satoken.stp.StpUtil;
import com.liu.common.entity.R;
import com.liu.common.entity.enums.PermissionEnum;
import com.liu.user.entity.base.UserPermissionInfo;
import com.liu.user.service.IUserPermissionInfoService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LiuChengLong
 * @since 2022-09-21
 */
@RestController
@RequestMapping("/user/userPermissionInfo")
public class UserPermissionInfoController {

    @Resource
    private IUserPermissionInfoService userPermissionInfoService;


    /**
     * 新增用户权限
     * @param userPermissionInfo 用户权限信息
     * @return R
     */
    @PostMapping("/addUserPermission")
    public R<String> addUserPermission(@RequestBody UserPermissionInfo userPermissionInfo){
        boolean hasPermission = StpUtil.hasPermissionOr(PermissionEnum.UPDATE_USER_PERMISSION.getCode(), PermissionEnum.IS_ADMIN.getCode());
        if (hasPermission){
            userPermissionInfoService.saveUserPermission(userPermissionInfo);
            return R.success();
        }else {
            return R.failed();
        }
    }

}

